{include file="/common/scripts" /}

<style>
    .goods-index .goods-item .goods-image {
        margin-right: 12px;
    }

    .goods-index .goods-item .goods-title {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        font-weight: 500;
        color: var(--sa-font);
    }

    .goods-index .goods-item .goods-subtitle {
        height: 16px;
        line-height: 16px;
        font-size: 12px;
        font-weight: 400;
        color: var(--sa-subfont);
        margin-bottom: 6px;
    }

    .goods-index .activity-tag {
        padding: 3px 8px;
        border-radius: 10px;
        line-height: 14px;
        font-size: 12px;
        font-weight: 400;
        margin-right: 8px;
        cursor: pointer;
    }

    .goods-index .activity-tag:last-of-type {
        margin-right: 0;
    }

    .goods-index .activity-tag.groupon,
    .goods-index .activity-tag.groupon_ladder {
        color: var(--el-color-primary);
        background: var(--t-bg-active);
    }

    .goods-index .activity-tag.seckill {
        color: #ff4d4f;
        background: rgba(255, 77, 79, .16);
    }

    .goods-index .activity-tag.promos {
        color: #faad14;
        background: rgba(250, 173, 20, 0.16);
    }

    .goods-index .sku {
        width: fit-content;
        height: 20px;
        line-height: 1;
        padding: 0 8px;
        font-size: 12px;
        color: #fff;
        background: var(--el-color-primary);
        border-radius: 10px;
        cursor: pointer;
    }

    .goods-index .sku .el-icon {
        margin-left: 4px;
    }

    .goods-index .add-stock {
        margin-left: 8px;
    }

    .goods-index .add-stock .iconfont {
        font-size: 12px;
        color: var(--el-color-primary);
    }

    .goods-index .sku-image {
        margin-left: 16px;
        margin-right: 28px;
    }

    .goods-index .sku-text {
        font-size: 12px;
        color: var(--sa-font);
    }

    .goods-index .price .el-input,
    .goods-index .sales .el-input {
        flex: 1;
    }

    .goods-index .price span,
    .goods-index .sales span {
        margin: 0 8px;
    }

    .goods-index .sa-table-wrap {
        height: 100%;
        margin-left: -48px;
        overflow: hidden;
    }

    .goods-index .sa-table-wrap .sa-expand-table .el-table__header-wrapper {
        display: none;
    }
    /*.exporttable {*/
    /*    border: solid 1px #c0c0c0;*/
    /*}*/
</style>

<div id="index" class="goods-index panel panel-default panel-intro" v-cloak>
    <el-container class="panel-block">
        <el-header class="sa-header">
            <el-tabs class="sa-tabs" v-model="state.filter.data.status" @tab-change="onChangeTab">
                <el-tab-pane v-for="sl in type.data.status" :key="sl" :label="sl.name" :name="sl.type">
                </el-tab-pane>
            </el-tabs>
            <div class="sa-title sa-flex sa-row-between">
                <div class="sa-title-left">
                    <div class="left-name">商品库</div>
                    <sa-filter-condition v-model="state.filter" @filter-delete="onChangeFilter">
                    </sa-filter-condition>
                </div>
                <div class="sa-title-right">
                    <el-button class="sa-button-refresh" icon="RefreshRight" @click="getData"></el-button>
                    <el-button class="sa-button-refresh" icon="Search" @click="onOpenFilter"></el-button>
                    <el-button icon="Plus" type="primary" @click="onAdd">添加</el-button>

<!--                    <el-button type="danger" icon="Delete" plain @click="onRecyclebin">回收站</el-button>-->

                </div>
            </div>
        </el-header>
        <el-main class="sa-main">
            <div class="sa-table-wrap">
                <el-table height="100%" class="sa-table exporttable"  :size="mini" :data="state.data" @selection-change="onChangeSelection"
                          @sort-change="onChangeSort" :expand-row-keys="expandRowKeys" row-key="id" stripe border   :header-cell-style="{border:'1px solid '}">
                    <el-table-column type="expand">
                        <template #default="props">
                            <el-table class="sa-table sa-expand-table" :data="state.data" stripe>
                                <el-table-column width="30"></el-table-column>
                                <el-table-column prop="id" label="ID" min-width="30"></el-table-column>
                            </el-table>
                        </template>
                    </el-table-column>

                    <el-table-column type="selection" width="30" align="center" ></el-table-column>
                    <el-table-column sortable="custom" prop="id" label="ID" min-width="30" ></el-table-column>
                    <el-table-column prop="title" label="商品名称"   width=""  resizable >
                    </el-table-column>

                    <el-table-column label="商品主图" prop="image">
                        <template #default="scope">
                            <div class="sa-flex">
                                <sa-image class="sku-image" :url="scope.row.image"
                                          size="32"></sa-image>
                            </div>
                        </template>
                    </el-table-column>

                    <el-table-column prop="goods_desc" label="商品简介" resizable="true" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column sortable="custom" prop="sales" label="销量" resizable >
                    </el-table-column>
                    <el-table-column sortable="custom" prop="price" label="价格">
                    </el-table-column>
                    <el-table-column sortable="custom" prop="views" label="浏览量">
                    </el-table-column>
                    <el-table-column sortable="custom" prop="likes" label="喜欢人数">
                    </el-table-column>

                    <el-table-column label="首页热门" prop="is_hot"  sortable="custom">

                        <template #default="scope">
                            <el-radio-group v-model="scope.row.is_hot">
                                <el-radio-button label="0" @input="onSetHot(scope.row.id,scope.row.is_hot)"  >非</el-radio-button>
                                <el-radio-button label="1" @input="onSetHot(scope.row.id,scope.row.is_hot)"  >热门</el-radio-button>
                            </el-radio-group>
                        </template>
                    </el-table-column>
                    <el-table-column label="首页技术" prop="is_hot" sortable="custom">

                        <template #default="scope">
                            <el-radio-group v-model="scope.row.is_technology">
                                <el-radio-button label="0" @input="onSetTechnology(scope.row.id,scope.row.is_technology)"  >非</el-radio-button>
                                <el-radio-button label="1" @input="onSetTechnology(scope.row.id,scope.row.is_technology)"  >技术</el-radio-button>
                            </el-radio-group>
                        </template>
                    </el-table-column>

                    <el-table-column  prop="status_texts" label="状态">
                    </el-table-column>
                    <el-table-column label="更新时间" width="172">
                        <template #default="scope">{{ scope.row.createtime || '-' }}</template>
                    </el-table-column>
                    <el-table-column label="操作"  fixed="right" >
                        <template #default="scope">
                            <div class="sa-flex">
                                <el-dropdown popper-class="goods-dropdown" @command="onCommand">
                                    <el-button link>
                                        <el-tag :type="state.statusData.type[scope.row.status]">
                                            {{ scope.row.status_text }}
                                            <el-icon>
                                                <arrow-down/>
                                            </el-icon>
                                        </el-tag>
                                    </el-button>
                                    <template #dropdown>
                                        <el-dropdown-menu>
                                            <template v-for="item in type.data.status">
                                                <el-dropdown-item v-if="item.type!='all'" :command="{
                                                    id: scope.row.id,
                                                    type: item.type,
                                                }">
                                                    <span :style="{color:state.statusData.color[item.type]}">
                                                        {{item.name}}
                                                    </span>
                                                </el-dropdown-item>
                                            </template>
                                        </el-dropdown-menu>
                                    </template>
                                </el-dropdown>
                                <el-button type="primary" link @click="onEdit(scope.row.id)">编辑</el-button>

<!--                                <el-button type="primary" link @click="onCopy(scope.row.id)">复制-->
<!--                                </el-button>-->
                                <el-popconfirm width="fit-content" confirm-button-text="确认" cancel-button-text="取消"
                                               title="确认删除这条记录?" @confirm="onDelete(scope.row.id)">
                                    <template #reference>
                                        <el-button type="danger" link>删除</el-button>
                                    </template>
                                </el-popconfirm>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </el-main>

        <el-footer class="sa-footer sa-flex sa-row-between sa-flex-wrap">
            <div class="sa-batch sa-flex">
                <div class="tip">
                    已选择 <span>{{batchHandle.data.length}}</span> 项
                </div>
                <div class="sa-flex">

                    <el-button type="danger" :disabled="!batchHandle.data.length" @click="onBatchHandle('delete')">删除
                    </el-button>


                    <el-button type="success" :disabled="!batchHandle.data.length" @click="onBatchHandle('up')">上架
                    </el-button>


                    <el-button type="danger" :disabled="!batchHandle.data.length" @click="onBatchHandle('down')">下架
                    </el-button>


                    <el-button type="info" :disabled="!batchHandle.data.length" @click="onBatchHandle('hidden')">隐藏
                    </el-button>
                </div>
            </div>
            <sa-pagination v-model="pagination" @pagination-change="getData"></sa-pagination>
        </el-footer>

    </el-container>
    <sa-filter v-model="state.filter" @filter-change="onChangeFilter">
        <template #supplement>
            <el-form-item class="price" label="价格区间">
                <el-input v-model="state.filter.data.price.min" placeholder="最低价格"></el-input>
                <span>至</span>
                <el-input v-model="state.filter.data.price.max" placeholder="最高价格"></el-input>
            </el-form-item>
            <el-form-item class="sales" :label="销量区间">
                <el-input v-model="state.filter.data.sales.min" placeholder="最低销量"></el-input>
                <span>至</span>
                <el-input v-model="state.filter.data.sales.max" placeholder="最高销量"></el-input>
            </el-form-item>
        </template>
    </sa-filter>
</div>
